<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0">
    <title>捐书订单</title>
    <link rel="stylesheet" type="text/css" href="../static/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="../static/css/donate_order.css"/>
    <link rel="stylesheet" type="text/css" href="../static/css/weui.min.css"/>
</head>
<body ontouchstart>
<div class="top_title">
    <div onclick="history.back()"><img class="back" src="../static/img/back_btn.png"/><span>返回</span></div>
    <div><span>捐书订单</span>&nbsp;&nbsp;&nbsp;&nbsp;</div>
    <div><img class="other" src="../static/img/other_btn.png"/></div>
</div>
<div class="top_place"></div>
<!--<div class="header">-->
    <!--<img src="../static/img/book_corner.png"/><br>-->
    <!--<span id="book_corner">去图书漂流角</span>-->
<!--</div>-->
<div class="content">
    <div id="donate_list"></div>
    <div class="sum_info">
        共<span class="donate_number"></span>本&nbsp;&nbsp;总熊猫币<span class="donate_integral"></span>
    </div>
</div>
<div class="bottom_btn">
    <span>确定</span>
</div>
</body>
<script type="text/javascript" src="../../static/js/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../static/js/weui.min.js"></script>
<script type="text/javascript" src="../../static/js/core/underscore.js"></script>
<script type="text/javascript" src="../../static/js/core/util.js"></script>
<script type="text/javascript" src="../../static/js/core/ocean.js"></script>
<script>
    var donate_number = 0;
    var donate_integral = 0;
    var donate_idstr = '';
    Window.onload = Load();

    function Load() {
        OrderList();
        $("#book_corner").click(function () {
            window.location.href = "book_corner.html"
        })
        $(".bottom_btn").click(function () {
            var corner = sessionStorage.getItem("ocean_corner");
            var loading = weui.loading('loading');
            $(".bottom_btn").addClass("no_btn");
            $(".bottom_btn").unbind();
            ocean.get("resources/biz/bc/api/donate/submit", {
                userId: ocean.getLoginUserId(),
                totalNum: donate_number,
                grade: donate_integral,
                isbns: donate_idstr,
                corner: corner
            }, function (res) {
                loading.hide();
                if (res.code == 0) {
                    sessionStorage.setItem("recycle-book-list", "");
                    window.location.href = "donate_success.html"
                }
            }, function (error) {
                ocean.tip(error);
            })
        })
    }

    function OrderList() {
        var bookArrStr = sessionStorage.getItem("recycle-book-list");
        if (bookArrStr) {
            var bookArr = JSON.parse(bookArrStr);
            for (var key in bookArr) {
                var book = bookArr[key];
                console.log(book)
                var str_list = '<div class="book_info">';
                str_list += '<span class="name">' + book.name + '</span>';
                str_list += '<span class="integral">熊猫币&nbsp;' + book.price + '</span>';
                str_list += '</div>';
                $("#donate_list").append(str_list);

                donate_number++;
                donate_integral += book.price;
                donate_idstr += book.isbn + ',';
            }
            $(".donate_number").text(donate_number);
            $(".donate_integral").text(donate_integral);
        } else {
            window.location.href = "donate_book.html";
        }
    }
</script>
</html>
